package com.feonix.common.util.jdbc;

import org.springframework.stereotype.Service;

import com.feonix.common.datasource.DataSourceSwitch;

@Service
public class SqlLimitFactory {
	public Dialect getDialect() {
		int i = DataSourceSwitch.getDbType();
		Dialect dialect = null;
		switch (i) {
		case 5:
			dialect = new MySQLDialect();
			break;
		case 1:
			dialect = new OracleDialect();
			break;
		case 2:
			dialect = new SQLServerDialect();
			break;
		case 3:
			dialect = new DB2Dialect();
			break;
		case 4:
			dialect = new SQLServerDialect();
			break;
		default:
			dialect = new MySQLDialect();
		}

		return (dialect);
	}

	public String getLimitedSql(String sql, int offset, int limit) {
		return getDialect().getLimitString(sql, offset, limit);
	}
}
